﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.DependencyInjection.Impl;

namespace StyleMVVM.DependencyInjection.Conditions
{
	/// <summary>
	/// Limits when an export can be used to only when the setting is equal to the value provided
	/// </summary>
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
	public class ExportWhenAppSettingAttribute : Attribute, IExportConditionAttribute
	{
		private readonly string settingName;
		private readonly object settingValue;
		private readonly bool cache;

		public ExportWhenAppSettingAttribute(string settingName, object settingValue)
		{
			this.settingName = settingName;
			this.settingValue = settingValue;
			this.cache = true;
		}

		public ExportWhenAppSettingAttribute(string settingName, object settingValue, bool cache)
		{
			this.settingName = settingName;
			this.settingValue = settingValue;
			this.cache = cache;
		}

		public IExportCondition ProvideCondition(Type exportType)
		{
			return new WhenAppSetting(settingName, settingValue, cache);
		}
	}
}